package com.linksfield.topup.config;

import com.linksfield.topup.interceptor.LoginInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;

/**
 * @author: lm
 * @date: 2019-11-21 15:40
 */
@Configuration
public class WebConfig extends WebMvcConfigurerAdapter {
    @Bean
    HandlerInterceptor getLoginInterceptor() {
        return new LoginInterceptor();
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //注册自定义拦截器，添加拦截路径和排除拦截路径
        InterceptorRegistration interceptor = registry.addInterceptor(getLoginInterceptor());
        //拦截所有路径
        interceptor.addPathPatterns("/**");
        //排除以下路径（不用登陆就可以访问的路径）
        interceptor.excludePathPatterns("/login");
        interceptor.excludePathPatterns("/unauth");
        interceptor.excludePathPatterns("/**.html");
        interceptor.excludePathPatterns("/swagger-ui.html/**");
        interceptor.excludePathPatterns("/swagger-resources/**");
        interceptor.excludePathPatterns("/v2/**");
        interceptor.excludePathPatterns("/webjars/**");
        interceptor.excludePathPatterns("/orderExport");
        interceptor.excludePathPatterns("/test");
    }
}
